#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->label->setText("00:00:00");
    time.setHMS(0,0,0);
    timer = new QTimer(this);
    connect(timer,&QTimer::timeout,this,&Widget::UpdateTime);



}

Widget::~Widget()
{
    delete ui;
}

//开始
void Widget::on_pushButton_star_clicked()
{

    timer->start(1000);

}
//显示
void Widget::UpdateTime()
{
    time = time.addSecs(1);
    ui->label->setText(time.toString());

}

//暂停
void Widget::on_pushButton_stop_clicked()
{

    timer->stop();

}
//记录
void Widget::on_pushButton_record_clicked()
{
    ui->textBrowser->append(ui->label->text());

}

void Widget::on_pushButton_reset_clicked()
{
    if(timer->isActive())
    {
        timer->stop();
    }
    time.setHMS(0,0,0);
    ui->label->setText("00:00:00");
}

void Widget::on_pushButton_clean_clicked()
{
    ui->textBrowser->clear();
}
